package com.zzyl;


import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;

import java.util.HashMap;
import java.util.Map;

public class HuToolTest1 {
    public static void main(String[] args) {
        String host = "https://aliv18.data.moji.com/whapi/json/alicityweather/forecast24hours";
        String appcode = "809ebd58fa424fccbf4f13f7e820cf7c";
        Map<String, String> headers = new HashMap<>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        Map<String, Object> bodys = new HashMap<>();
        bodys.put("token", "27200005b3475f8b0e26428f9bfb13e9");
        bodys.put("cityId", "2");


        try {
            HttpResponse response = HttpUtil.createRequest(Method.POST, host)
                    .header("Authorization", "APPCODE " + appcode)
                    //.body(JSON.toJSONString(bodys))
                    .form(bodys)
                    .execute();
            System.out.println(response.body());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
